package cn.edu.klmy.spring.filter;

import com.google.code.kaptcha.Constants;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 验证码过滤器，在登陆验证之前
 * @author 顾伟
 *         创建日期：13-4-3
 */
public class VerifyCodeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        String verifyCode=request.getParameter("kaptcha");
        String code = (String)request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);

        filterChain.doFilter(request, response);
        //判断验证码
//        if(code.equals(verifyCode)){
//            filterChain.doFilter(request, response);
//        }else{
//            response.sendRedirect("login/failure");
//        }
    }

    @Override
    public void destroy() {

    }
}
